package com.woniu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.been.entity.TLogin;
import com.woniu.been.entity.Teachers;
import com.woniu.mapper.TeachersMapper;

import com.woniu.service.TeachersService;
import com.woniu.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeachersServiceImpl implements TeachersService {
    @Autowired
    private TeachersMapper teachersMapper;
    /*
    * 登录
    * */
    @Override
    public Teachers login(String teacherName, String password) {
        return teachersMapper.login(teacherName,password);
    }

    /*
    * 动态查询所有老师并进行分页
    * */
    @Override
    public PageResult findAllTeacher(Teachers teachers, Integer pageNum, Integer pageSize) {
        //设置当前页和每页记录数
        PageHelper.startPage(pageNum,pageSize);
        //调用mapper方法
        List<Teachers> list = teachersMapper.findAllTeacher(teachers);
        //创建PageInfo对象
        PageInfo<Teachers> pageInfo = new PageInfo<>(list);
        //封装响应数据
        PageResult ps = new PageResult(pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getTotal(), pageInfo.getList());
        return ps;
    }

    /*
    * 根据姓名和手机号查询老师（目的:判断该用户名或者手机号是否存在 如果存在则不允许注册）
    * */
    @Override
    public List<Teachers> findTeacherByNameAndTelephone(String teacherName, String telephone) {
        return teachersMapper.findTeacherByNameAndTelephone(teacherName,telephone);
    }

    /*
    * 注册老师信息
    * */
    @Override
    public void register(Teachers teachers) {
        teachersMapper.register(teachers);
    }

    @Override
    public void deleteTeacher(Integer teacherId) {
        teachersMapper.deleteTeacher(teacherId);
    }

    @Override
    public void updateTeacher(Teachers teachers) {
        teachersMapper.updateTeacher(teachers);
    }

    @Override
    public String findTeacherRoleByTeacherName(String teacherName) {
        return teachersMapper.findTeacherRoleByTeacherName(teacherName);
    }

    @Override
    public String findTeacherRoleByTelephone(String telephone) {
        return teachersMapper.findTeacherRoleByTelephone(telephone);
    }

    @Override
    public void addAdmin(Teachers teachers) {
        teachersMapper.addAdmin(teachers);
    }

    @Override
    public Teachers findTeacherByName(String teacherName) {
        return teachersMapper.findTeacherByName(teacherName);
    }

    @Override
    public List<Teachers> findTeacherNotContainItself(String teacherName, String telephone, Integer teacherId) {
        return teachersMapper.findTeacherNotContainItself(teacherName,telephone,teacherId);
    }

    @Override
    public String findTeacherNameByTelephone(String telephone) {
        return teachersMapper.findTeacherNameByTelephone(telephone);
    }

    @Override
    public void updateByUsername(String imagePath, String teacherName) {
        teachersMapper.updateByUsername(imagePath,teacherName);
    }

    @Override
    public Integer findRoleByTeacherId(Integer teacherId) {
        return teachersMapper.findRoleByTeacherId(teacherId);
    }

    @Override
    public Teachers findTeacherById(Integer teacherId) {
        return teachersMapper.findTeacherById(teacherId);
    }

    @Override
    public void updateTeacherRole(String teacherName, Integer role) {
        teachersMapper.updateTeacherRole(teacherName,role);
    }
}
